<?php

namespace App\Notifications;

use App\Channels\WechatChannel;
use App\Lead;
use EasyWeChat\Kernel\Messages\Text;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Support\Carbon;

class LeadsNotification extends Notification implements  ShouldQueue
{
    use Queueable;
    protected  $lead;
    /**
     * Create a new notification instance.
     *
     * @return void
     */
    public function __construct(Lead $lead)
    {
        $this->lead=$lead;
    }

    /**
     * Get the notification's delivery channels.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function via($notifiable)
    {
        return [WechatChannel::class];
    }
    public function toWechat(){
        $name=$this->lead->name;

        $mobile=substr_replace($this->lead->mobile, '****',3, 4);
        $leadsId=$this->lead->leads_id;
        $url=config('mweb.web_url')."/#/CRM/leads/detail?id=$leadsId";
        $url=config('mweb.crm').'/url/'.base64_encode($url);
        $source=$this->lead->source;
        $time=Carbon::now()->toDateString();
        if ($this->lead->owner){
            $ownerName=$this->lead->owner->realname;
        }else{
            $ownerName='全体成员';
        }
     //   $message=   sprintf("线索提醒\n线索名称：%s \n线索来源：头条\n手机号码：%s \n线索编号：%s \n跟进人：%s \n<a href='%s '>请跟进人及时跟进，并反馈详细信息到系统！</a>",$name,$mobile,$leadsId,$ownerName,$url);
       $message= new Text("线索提醒\n线索名称：$name\n手机号码：$mobile\n线索编号：$leadsId\n跟进人：$ownerName\n时间：$time<a href='$url'>请5分钟内跟进，并反馈详细信息到系统！</a>");
        return $message;
    }
    /**
     * Get the mail representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return \Illuminate\Notifications\Messages\MailMessage
     */
    public function toMail($notifiable)
    {
        return (new MailMessage)
                    ->line('The introduction to the notification.')
                    ->action('Notification Action', url('/'))
                    ->line('Thank you for using our application!');
    }

    /**
     * Get the array representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function toArray($notifiable)
    {
        return [


        ];
    }
}
